<%--
  Created by IntelliJ IDEA.
  User: barton
  Date: 16-5-17
  Time: 下午3:36
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>SSE</title>
    <script src="/js/jquery-2.2.3.js"></script>
    <script>
        if (!!window.EventSource) {
            var source = new EventSource('push');

            s = '';

            source.addEventListener('message', function (e) {
                s += e.data + "<br />";
                $("#msgFromPush").html(s);
            });

            source.addEventListener('open', function (e) {
                console.log("链接打开");
            }, false);

            source.addEventListener('error', function (e) {
                if (e.readyState == EventSource.CLOSED) {
                    console.log("链接关闭");
                } else {
                    console.log(e.readyState);
                }
            }, false);

        } else {
            console.log("您的浏览器不支持sse!");
        }
    </script>
</head>
<body>
<div id="msgFromPush"></div>
</body>
</html>
